<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<form id="pagerForm" method="get" model="viewRequest" action="${rootUrl}/order/sales-return/${salesReturn.id}/edit">
</form>
<div class="pageContent">
	<form id="mainFormId" method="post" action="${rootUrl}/order/sales-return<c:if test="${salesReturn.id != 0 && salesReturn.id != '' }">/${salesReturn.id}</c:if>" class="pageForm required-validate" onsubmit="return validateCallback(this, newDialogAjaxDone);">
		<c:if test="${salesReturn.id != 0 && salesReturn.id != '' }"><input type="hidden" name="_method" value="put"></c:if>
		<input type="hidden" name="salesReturn.id" value="${salesReturn.id }">
		<input type="hidden" name="salesReturn.order.id" value="${salesReturn.id }">
		<div class="pageFormContent" layoutH="56">
			<div class="tabs" currentIndex="0" eventType="click">
				<div class="tabsHeader">
					<div class="tabsHeaderContent">
						<ul>
							<li><a href="javascript:;"><span>退款详情</span></a></li>
							<li><a href="javascript:;"><span>订单详情</span></a></li>
						</ul>
					</div>
				</div>
				<div class="tabsContent">
					<div>
						<p>
							<label>订单编号：</label>
							<input name="salesReturn.order.code" readonly="readonly" type="text" size="30" value="${salesReturn.order.code }" />
						</p>
						<p>
							<label>买家：</label>
							<input readonly="readonly" type="text" value="${salesReturn.order.member.loginname}" />
							<a class="buttonActive" href="${rootUrl}/member/member!detail?id=${salesReturn.member.id}" title="会员详情" buttonActiverel="member_detail_orders" rel="member_detail" target="dialog" width="800" height="600"><span>会员详情</span></a>
						</p>
						<p>
							<label>申请退款金额：</label>
							<input readonly="readonly" type="text" size="30" value="<fmt:formatNumber value="${salesReturn.applyAmount/100}" pattern="0.00"/>" />
						</p>
						<p>
							<label>实际退款金额：</label>
							<input name="returnPrice" class="required" max="<fmt:formatNumber value="${salesReturn.applyAmount/100}" pattern="0.00"/>" <c:if test="${salesReturn.state != 0}">readonly="readonly"</c:if> id="returnMoneyId"
							 onfocus="if (value =='0.00'){value =''}" onblur="if (value ==''){value='0.00'}" type="text" size="30" value="<fmt:formatNumber value="${salesReturn.refundAmount/100}" pattern="0.00"/>" />
						</p>
						<p>
							<label>退货类型：</label>
							<input id="returnTypeId" readonly="readonly" type="text" size="30" value="<c:if test="${salesReturn.type == '1'}">退货退款</c:if><c:if test="${salesReturn.type == '2'}">仅退款</c:if>" />
						</p>
						<p>
							<label>退款状态：</label>
							<input readonly="readonly" id="statTxtId" type="text" size="30" value="<c:if test="${salesReturn.state ==0 }">待审核</c:if><c:if test="${salesReturn.state ==1 }">审核通过</c:if><c:if test="${salesReturn.state ==2 }">审核不通过</c:if><c:if test="${salesReturn.state ==3 }">退货成功</c:if><c:if test="${salesReturn.state ==4 }">退货失败</c:if>" />
							<input name="salesReturn.state" id="statValueId" type="hidden" size="30" value="${salesReturn.state }" />
						</p>
						<p>
							<label>备注退款说明：</label>
							<input name="salesReturn.remark" readonly="readonly" type="text" size="30" value="${salesReturn.remark }" />
						</p>
						<p>
							<label>处理人：</label>
							<input name="" readonly="readonly" type="text" size="30" value="${user.username }" />
						</p>
						<p>
							<label>申请时间：</label>
							<input name="salesReturn.createdAt" readonly="readonly" type="text" size="30" value="<fmt:formatDate value='${salesReturn.createdAt}' pattern="yyyy-MM-dd HH:mm:ss"/>" />
						</p>
						<p>
							<label>回复：</label>
							<input name="salesReturn.reply" <c:if test="${salesReturn.state != 0}">readonly="readonly"</c:if> type="text" size="30" value="${salesReturn.reply }" />
						</p>
						<p>
							<label>退款时间：</label>
							<input name="salesReturn.refundTime" readonly="readonly" type="text" size="30" value="<fmt:formatDate value='${salesReturn.refundTime}' pattern="yyyy-MM-dd HH:mm:ss"/>" />
						</p>
						<p>
							<label>退款图片：</label>
							<a class="btnLook" href="${rootUrl}/order/sales-return/${salesReturn.id}/images" width="800" height="720" lookupGroup="member">图片</a>
						</p>
					</div>
					<div>
						<p>
							<label>订单编号：</label>
							<input readonly="readonly" type="text" size="30" value="${salesReturn.order.code }" />
						</p>
						<p>
							<label>买家：</label>
							<input readonly="readonly" type="text" size="30" value="${salesReturn.order.member.loginname}" />
						</p>
						<p>
							<label>支付单号：</label>
							<input name="" readonly="readonly" type="text" size="30" value="${salesReturn.order.payCode }" />
						</p>
						<p>
							<label>支付渠道：</label>
							<input readonly="readonly" type="text" size="30" value="${salesReturn.order.payChannel }" />
						</p>
						<p>
							<label>支付时间：</label>
							<input name="" readonly="readonly" type="text" size="30" value="<fmt:formatDate value='${salesReturn.order.payTime}' pattern="yyyy-MM-dd HH:mm:ss"/>" />
						</p>
						<p>
							<label>商品金额：</label>
							<input readonly="readonly" type="text" size="30" value="<fmt:formatNumber value="${salesReturn.order.goodsAmount/100}" pattern="0.00"/>" />
						</p>
						<p>
							<label>优惠金额：</label>
							<input name="" readonly="readonly" type="text" size="30" value="<fmt:formatNumber value="${salesReturn.order.discountAmount/100}" pattern="0.00"/>" />
						</p>
						<p>
							<label>订单金额：</label>
							<input readonly="readonly" type="text" size="30" value="<fmt:formatNumber value="${salesReturn.order.orderAmount/100}" pattern="0.00"/>" />
						</p>
						<p>
							<label>运费金额：</label>
							<input name="" readonly="readonly" type="text" size="30" value="<fmt:formatNumber value="${salesReturn.order.freightAmount/100}" pattern="0.00"/>" />
						</p>
						<p>
							<label>应付金额：</label>
							<input readonly="readonly" type="text" size="30" value="<fmt:formatNumber value="${salesReturn.order.resultAmount/100}" pattern="0.00"/>" />
						</p>
						<p>
							<label>退款金额：</label>
							<input name="" readonly="readonly" type="text" size="30" value="<fmt:formatNumber value="${salesReturn.order.refundAmount/100}" pattern="0.00"/>" />
						</p>
						<%-- <p>
							<label>订单状态：</label>
							<input name="" readonly="readonly" type="text" size="30" value="${orderState[salesReturn.order.state]}" />
						</p> --%>
						<p>
							<label>下单时间：</label>
							<input readonly="readonly" type="text" size="30" value="<fmt:formatDate value='${salesReturn.order.createdAt}' pattern="yyyy-MM-dd HH:mm:ss"/>" />
						</p>
						<p>
							<label>取消时间：</label>
							<input readonly="readonly" type="text" size="30" value="<fmt:formatDate value='${salesReturn.order.cancelTime}' pattern="yyyy-MM-dd HH:mm:ss"/>" />
						</p>
						<p>
							<label>退款时间：</label>
							<input readonly="readonly" type="text" size="30" value="<fmt:formatDate value='${salesReturn.order.refundTime}' pattern="yyyy-MM-dd HH:mm:ss"/>" />
						</p>
						<p>
							<label>完成时间：</label>
							<input readonly="readonly" type="text" size="30" value="<fmt:formatDate value='${salesReturn.order.finishTime}' pattern="yyyy-MM-dd HH:mm:ss"/>" />
						</p>
						<p>
							<label>收货地址：</label>
							<input name="" readonly="readonly" type="text" size="30" value="${salesReturn.order.address }" />
						</p>
					</div>
				</div>
			</div>
			<div class="tabs" currentIndex="0" eventType="click">
				<div class="tabsHeader">
					<div class="tabsHeaderContent">
						<ul>
							<c:forEach items="${salesReturn.order.storageOrder}" var="storageOrder" varStatus="status">
								<li><a href="javascript:;"><span>${storageOrder.storage.name}</span></a></li>
							</c:forEach>
						</ul>
					</div>
				</div>
				<div class="tabsContent">
				<c:forEach items="${salesReturn.order.storageOrder}" var="storageOrder" varStatus="status">
					<div>
						<fieldset>
							<legend>二级订单详情</legend>
							<p>
								<label>二级订单编号：</label>
								<input readonly="readonly" type="text" size="30" value="${storageOrder.code }" />
							</p>
							<p>
								<label>商家：</label>
								<input name="" readonly="readonly" type="text" size="30" value="${storageOrder.seller.name }" />
							</p>
							<p>
								<label>快递名称：</label>
								<input name="" readonly="readonly" type="text" size="30" value="${storageOrder.express.name }" />
							</p>
							<p>
								<label>快递单号：</label>
								<input name="" readonly="readonly" type="text" size="30" value="${storageOrder.expressCode }" />
							</p>
							<p>
								<label>重量(克)：</label>
								<input name="" readonly="readonly" type="text" size="30" value="${storageOrder.weight }" />
							</p>
							<p>
								<label>运费：</label>
								<input name="" readonly="readonly" type="text" size="30" value="<fmt:formatNumber value="${storageOrder.freight/100}" pattern="0.00"/>" />
							</p>
							<p>
								<label>超重运费：</label>
								<input name="" readonly="readonly" type="text" size="30" value="<fmt:formatNumber value="${storageOrder.overweightFreight/100}" pattern="0.00"/>" />
							</p>
							<p>
								<label>发货时间：</label>
								<input name="" readonly="readonly" type="text" size="30" value="<fmt:formatDate value='${storageOrder.deliveryTime }' pattern="yyyy-MM-dd HH:mm:ss"/>" />
							</p>
							<p>
								<label>确认收货时间：</label>
								<input name="" readonly="readonly" type="text" size="30" value="<fmt:formatDate value='${storageOrder.receiptTime }' pattern="yyyy-MM-dd HH:mm:ss"/>" />
							</p>
							<p>
								<label>截至收货时间：</label>
								<input name="" readonly="readonly" type="text" size="30" value="<fmt:formatDate value='${storageOrder.receiptEndTime }' pattern="yyyy-MM-dd HH:mm:ss"/>" />
							</p>
							<p>
								<label>退款时间：</label>
								<input name="" readonly="readonly" type="text" size="30" value="<fmt:formatDate value='${storageOrder.refundTime }' pattern="yyyy-MM-dd HH:mm:ss"/>" />
							</p>
							<p>
								<label>商品总价格：</label>
								<input readonly="readonly" type="text" size="30" value="<fmt:formatNumber value="${storageOrder.goodsAmount/100}" pattern="0.00"/>" />
							</p>
							<p>
								<label>优惠金额：</label>
								<input name="" readonly="readonly" type="text" size="30" value="<fmt:formatNumber value="${storageOrder.discountAmount/100}" pattern="0.00"/>" />
							</p>
							<p>
								<label>应付价格：</label>
								<input name="" readonly="readonly" type="text" size="30" value="<fmt:formatNumber value="${storageOrder.resultAmount/100}" pattern="0.00"/>" />
							</p>
							<p>
								<label>退款金额：</label>
								<input name="" readonly="readonly" type="text" size="30" value="<fmt:formatNumber value="${storageOrder.refundAmount/100}" pattern="0.00"/>" />
							</p>
							<%-- <p>
								<label>订单状态：</label>
								<input name="" readonly="readonly" type="text" size="30" value="${orderState[storageOrder.state] }" />
							</p> --%>
							<p>
								<label>完成时间：</label>
								<input name="" readonly="readonly" type="text" size="30" value="${storageOrder.finishTime }" />
							</p>
							<p>
								<label>是否延期收货：</label>
								<input name="" readonly="readonly" type="text" size="30" value="<c:if test="${storageOrder.isDelayed == 0}">否</c:if><c:if test="${storageOrder.isDelayed == 1}">是</c:if>" />
							</p>
							<p style="width: 1100px">
								<label>买家留言：</label>
								<input name="" readonly="readonly" type="text" size="155" value="${storageOrder.remark }" />
							</p>
						</fieldset>
						<div>
							<table class="table" targetType="dialog"  width="100%">
								<thead>
									<tr>
										<th width="30" align="center" >序号</th>
										<th width="100">三级订单编号</th>
										<th width="150">商品名称</th>
										<th width="150">商品规格</th>
										<th width="70">商品单价</th>
										<th width="70">购买数量</th>
										<th width="50">总价</th>
										<th width="50">积分</th>
										<th width="50">重量</th>
										<th width="70">虚拟商品</th>
										<th width="100">七天无理由退换</th>
										<th width="70">订单状态</th>
										<th width="100">退款金额</th>
										<th width="100">退款时间</th>
										<th width="100">完成时间</th>
										<th width="100">是否退款</th>
										<th width="100">退款数量</th>
									</tr>
								</thead>
								<tbody>
								<c:forEach items="${storageOrder.goodsOrder}" var="goodsOrder" varStatus="status">
									<tr target="data_id" rel="${salesReturn.order.id}">
										<td>${status.count}</td>
										<td>${goodsOrder.code}</td>
										<td>${goodsOrder.name}</td>
										<td>${goodsOrder.spec}</td>
										<td class="listMoneyField"><fmt:formatNumber value="${goodsOrder.price/100}" pattern="0.00"/></td>
										<td class="listMoneyField">${goodsOrder.num}</td>
										<td class="listMoneyField"><fmt:formatNumber value="${goodsOrder.totals/100}" pattern="0.00"/></td>
										<td class="listMoneyField">${goodsOrder.points}</td>
										<td class="listMoneyField">${goodsOrder.weight}</td>
										<td><c:if test="${goodsOrder.isVirtual == 0}">否</c:if><c:if test="${goodsOrder.isVirtual == 1}">是</c:if></td>
										<td><c:if test="${goodsOrder.isSevenDaysReturned == 0}">否</c:if><c:if test="${goodsOrder.isSevenDaysReturned == 1}">是</c:if></td>
										<td>${orderState[goodsOrder.state]}</td>
										<td class="listMoneyField"><fmt:formatNumber value="${goodsOrder.refundAmount/100}" pattern="0.00"/></td>
										<td><fmt:formatDate value="${goodsOrder.refundTime}" pattern="yyyy-MM-dd HH:mm:ss"/></td>
										<td><fmt:formatDate value="${goodsOrder.finishTime}" pattern="yyyy-MM-dd HH:mm:ss"/></td>
										<td>
											<c:forEach var="item" items="${salesReturnMap}">   
												<c:if test="${goodsOrder.id == item.key}"><font color="red">是</font></c:if>
											</c:forEach>
										</td>
										<td>
											<c:forEach var="item" items="${salesReturnMap}">   
												<c:if test="${goodsOrder.id == item.key}">${item.value}</c:if>
											</c:forEach>
										</td>
									</tr>
								</c:forEach>
								</tbody>
							</table>
						</div>
					</div>
				</c:forEach>
				</div>
			</div>
	
	
   		 </div>
    	<div class="formBar">
			<ul>
				<li id="delivered"><div class="<c:if test="${salesReturn.state != 0}">buttonDisabled</c:if><c:if test="${salesReturn.state == 0}">buttonActive</c:if>"><div class="buttonContent"><button <c:if test="${salesReturn.state != 0}">disabled="disabled"</c:if> onclick="sales_return()" type="button">通过</button></div></div></li>
				<li id="delivered"><div class="<c:if test="${salesReturn.state != 0}">buttonDisabled</c:if><c:if test="${salesReturn.state == 0}">buttonActive</c:if>"><div class="buttonContent"><button <c:if test="${salesReturn.state != 0}">disabled="disabled"</c:if> onclick="reject()" type="button">不通过</button></div></div></li>
				<li id="delivered"><div class="<c:if test="${salesReturn.state != 1}">buttonDisabled</c:if><c:if test="${salesReturn.state == 1}">buttonActive</c:if>"><div class="buttonContent"><button <c:if test="${salesReturn.state != 1}">disabled="disabled"</c:if> onclick="success()" type="button">退货成功</button></div></div></li>
				<li id="delivered"><div class="<c:if test="${salesReturn.state != 1}">buttonDisabled</c:if><c:if test="${salesReturn.state == 1}">buttonActive</c:if>"><div class="buttonContent"><button <c:if test="${salesReturn.state != 1}">disabled="disabled"</c:if> onclick="fail()" type="button">退货失败</button></div></div></li>
			<li>
				<div class="button"><div class="buttonContent"><button type="button" class="close">关闭</button></div></div>
			</li>
		</ul>
	</div>
   </form>
    
</div>
<script>
	function sales_return(){
		var returnType = $("#returnTypeId").val();
		var returnMoney = $("#returnMoneyId").val();
		alertMsg.confirm("确定要"+returnType+"该订单吗？<br>订单号：${salesReturn.order.code }<br>要求退款额：<fmt:formatNumber value="${salesReturn.applyAmount/100}" pattern="0.00"/><br>实际退款额：<font color=\"red\">"+returnMoney+"</font>", {
			okCall: function(){
				$("#statValueId").val("1");
				$("#mainFormId").attr("action","${rootUrl}/order/sales-return/${salesReturn.order.id}/pass");
				$("#mainFormId").submit();
			}
		});
	}
	function reject(){
		alertMsg.confirm("确定要审核不通过该订单吗？<br>订单号：${salesReturn.order.code }<br>要求退款额：<fmt:formatNumber value="${salesReturn.applyAmount/100}" pattern="0.00"/><br>实际退款额：<font color=\"red\">0</font>", {
			okCall: function(){
				var returnType = $("#returnTypeId").val();
				$("#returnMoneyId").val("0");
				$("#statValueId").val("2");
				$("#mainFormId").attr("action","${rootUrl}/order/sales-return/${salesReturn.order.id}/reject");
				$("#mainFormId").submit();
			}
		});
	}
	
	function success(){
		alertMsg.confirm("确定要退货成功该订单吗？", {
			okCall: function(){
				$("#mainFormId").attr("action","${rootUrl}/order/sales-return/${salesReturn.order.id}/success");
				$("#mainFormId").submit();
			}
		});
	}
	
	function fail(){
		alertMsg.confirm("确定要退货失败该订单吗？", {
			okCall: function(){
				$("#mainFormId").attr("action","${rootUrl}/order/sales-return/${salesReturn.order.id}/fail");
				$("#mainFormId").submit();
			}
		});
	}
</script>
